﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace csharp_ude_charset
{
    class Program
    {
        public const int euckrCodePage = 51949;
        
        static void Main(string[] args)
        {
            string str = "가나";

            Ude.CharsetDetector charsetDetector = new Ude.CharsetDetector();
            byte[] buffer = Encoding.UTF8.GetBytes(str);
            using (MemoryStream memoryStream = new MemoryStream(buffer))
            {
                charsetDetector.Feed(memoryStream);
                charsetDetector.DataEnd();
            }
            string charset = charsetDetector.Charset;
            Console.WriteLine(BitConverter.ToString(buffer));
            Console.WriteLine("{0}: {1}", str, charset);

            byte[] encodeBuffer = Encoding.GetEncoding(euckrCodePage).GetBytes(str);
            string encodeStr = Encoding.GetEncoding(euckrCodePage).GetString(encodeBuffer);
            using (MemoryStream memoryStream = new MemoryStream(encodeBuffer))
            {
                charsetDetector.Feed(memoryStream);
                charsetDetector.DataEnd();
            }
            string encodeCharset = charsetDetector.Charset;
            Console.WriteLine(BitConverter.ToString(encodeBuffer));
            Console.WriteLine("{0}: {1}", encodeStr, encodeCharset);

            Console.Write("press anykey...");
            Console.ReadKey();
        }
    }
}
